﻿using System;
using System.IO;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using FrameWork.web.Code;
using FrameWork.Entity;
using FrameWork.Components;

namespace FrameWork.web.Module.ITMS.Service
{
    public partial class CreateService : System.Web.UI.Page
    {
        /// <summary>
        /// 首次派单人员通知方式(0:不填 1:邮件 2:短消息 3: 全选)
        /// </summary>
        protected int FstUserNotify
        {

            get
            {
                if (chkFirstUserEmail.Checked && chkFirstUserMsg.Checked)
                {
                    return 3;
                }
                else if (chkFirstUserEmail.Checked)
                {
                    return 1;
                }
                else if (chkFirstUserMsg.Checked)
                {
                    return 2;
                }
                else
                {
                    return 0;
                }
                
            }
        }

        /// <summary>
        /// 首次派单关注人通知方式(0:不填 1:邮件 2:短消息 3: 全选)
        /// </summary>
        protected int FstAttPSNNotify
        {

            get
            {
                if (chkFirstAttEmail.Checked && chkFirstAttMsg.Checked)
                {
                    return 3;
                }
                else if (chkFirstUserEmail.Checked)
                {
                    return 1;
                }
                else if (chkFirstUserMsg.Checked)
                {
                    return 2;
                }
                else
                {
                    return 0;
                }

            }
        }

        /// <summary>
        /// 硬件更换信息通知方式(0:不填 1:邮件 2:短消息 3: 全选)
        /// </summary>
        protected int HardNoticeType
        {

            get
            {
                if (chkHardNoticeEmail.Checked && chkHardNoticeMsg.Checked)
                {
                    return 3;
                }
                else if (chkHardNoticeEmail.Checked)
                {
                    return 1;
                }
                else if (chkHardNoticeMsg.Checked)
                {
                    return 2;
                }
                else
                {
                    return 0;
                }

            }
        }

        /// <summary>
        /// IP地址更换信息通知方式(0:不填 1:邮件 2:短消息 3: 全选)
        /// </summary>
        protected int IpAddrNoticeType
        {

            get
            {
                if (chkIPAddrNotifyEmail.Checked && chkIPAddrNotifyMsg.Checked)
                {
                    return 3;
                }
                else if (chkIPAddrNotifyEmail.Checked)
                {
                    return 1;
                }
                else if (chkIPAddrNotifyMsg.Checked)
                {
                    return 2;
                }
                else
                {
                    return 0;
                }

            }
        }

        /// <summary>
        /// 二次派单人员通知方式(0:不填 1:邮件 2:短消息 3: 全选)
        /// </summary>
        protected int SecUserNotify
        {

            get
            {
                if (chkSecUserEmail.Checked && chkSecUserMsg.Checked)
                {
                    return 3;
                }
                else if (chkSecUserEmail.Checked)
                {
                    return 1;
                }
                else if (chkSecUserMsg.Checked)
                {
                    return 2;
                }
                else
                {
                    return 0;
                }

            }
        }

        /// <summary>
        ///  二次派单关注人员通知方式(0:不填 1:邮件 2:短消息 3: 全选)
        /// </summary>
        protected int SecAttNotify
        {

            get
            {
                if (chkSecAttEmail.Checked && chkSecAttMsg.Checked)
                {
                    return 3;
                }
                else if (chkSecAttEmail.Checked)
                {
                    return 1;
                }
                else if (chkSecAttMsg.Checked)
                {
                    return 2;
                }
                else
                {
                    return 0;
                }

            }
        }

        /// <summary>
        /// 附件URL
        /// </summary> 
        /// 
        private string _urlPath = "";

        private string urlPath
        {
            get
            {
                return _urlPath;
            }
            set
            {
                _urlPath = value;
            }
        }

        /// <summary>
        /// 保存附件
        /// </summary>
        /// <returns></returns>
        private bool UpPhoto()
        {
            if (this.U_PhotoUrl.FileName == "")
            {
                return false;
            }

            //判断文件夹是否存在，不存在创建该文件夹
            DirectoryInfo di = new DirectoryInfo(Server.MapPath(Common.UpLoadDir + "Service"));
            //DirectoryInfo di = new DirectoryInfo("c:\\Service");
            if (!di.Exists)
            {
                di.Create();
            }
            FileUpLoadCommon fc = new FileUpLoadCommon(Common.UpLoadDir + "Service/", false);
            fc.SaveFile(U_PhotoUrl, true);

            urlPath = fc.fileName_s.Substring(2);
            return true;
        }

        /// <summary>
        /// 绑定解决方案
        /// </summary>
        private void bindResolvent()
        {
            its_ResolventEntity re = new its_ResolventEntity();
            re.UID = 0;
            its_ResolventCs reCs = new its_ResolventCs();
            DataTable dt = reCs.GetResolvent(re);
            DataRow dr = dt.NewRow();
            dr["UID"] = -1;
            dr["Title"] = "请选择";
            dt.Rows.InsertAt(dr, 0);
            this.drpResolvent.DataValueField = "UID";
            this.drpResolvent.DataTextField = "Title";
            this.drpResolvent.DataSource = dt;
            this.drpResolvent.DataBind();
            this.drpResolvent.SelectedIndex = -1;
        }
       
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                chkFirstAlloc.Checked = true;
                //获取邮件配置信息
                GetMailInfo();

                sys_UserTable ut = BusinessFacade.sys_UserDisp(Common.Get_UserID);
                txtFirstUserName.Text = ut.U_CName;
                txtFirstUserID.Text = ut.UserID.ToString();
              
                //绑定故障分类
                sys_FieldValue sfTroubType = new sys_FieldValue();
                sfTroubType.V_F_Key = "TroubType";
                its_FieldValueCs sfTroubTypeCs = new its_FieldValueCs();
                DataTable dtTroubType = sfTroubTypeCs.Field_SelectInfoByF_Key(sfTroubType);
                this.drpServTrobType.DataTextField = "V_Text";
                this.drpServTrobType.DataValueField = "ValueID";
                this.drpServTrobType.DataSource = dtTroubType;
                this.drpServTrobType.DataBind();
                //绑定问题分类
                sys_FieldValue sfProbType = new sys_FieldValue();
                sfProbType.V_F_Key = "ProbType";
                its_FieldValueCs sfProbTypeCs = new its_FieldValueCs();
                DataTable dtsfProbType = sfProbTypeCs.Field_SelectInfoByF_Key(sfProbType);
                this.drpServProbType.DataTextField = "V_Text";
                this.drpServProbType.DataValueField = "ValueID";
                this.drpServProbType.DataSource = dtsfProbType;
                this.drpServProbType.DataBind();
                //绑定报修人部门
                sys_Group sg = new sys_Group();
                its_GroupCs sgCs=new its_GroupCs();
                DataTable dtGroup = sgCs.Group_SelectInfo(sg);
                this.drpGroup.DataTextField = "G_CName";
                this.drpGroup.DataValueField = "GroupID";
                this.drpGroup.DataSource = dtGroup;
                this.drpGroup.DataBind();
                //绑定服务单号
                its_DocNoTable id = new its_DocNoTable();
                its_ServiceDocCs isCs = new its_ServiceDocCs();
                this.txtServDocNo.Text= isCs.GetDocNo(id);

                //绑定解决方案
                bindResolvent();
            }
        }
       
        private bool Check()
        {
            if (txtRepUserNO.Text.Trim() == "")
            {
                this.ClientScript.RegisterStartupScript(this.GetType(), "key1", "<script>alert('报修人工号不能为空');</script>");
                return false;
            }
            else if (txtRepUserName.Text.Trim() == "")
            {
                this.ClientScript.RegisterStartupScript(this.GetType(), "key2", "<script>alert('报修人姓名不能为空');</script>");
                return false;
            }
            else if (txtRepTitle.Text.Trim() == "")
            {
                this.ClientScript.RegisterStartupScript(this.GetType(), "key3", "<script>alert('报修标题不能为空');</script>");
                return false;
            }
            else if (txtFirstUserName.Text.Trim() == "")
            {
                this.ClientScript.RegisterStartupScript(this.GetType(), "key4", "<script>alert('首次派单人员不能为空');</script>");
                return false;
            }
            return true;
        }

        private void DocFinish()
        {
            try
            {
                //服务单主表类
                its_ServiceDoc serDoc = new its_ServiceDoc();
                //服务单派单表类
                its_ServiceAllotDoc serAllocDoc = new its_ServiceAllotDoc();

                serDoc.ServDocNo = txtServDocNo.Text.Trim();
                serDoc.RepUserNO = txtRepUserNO.Text.Trim();
                serDoc.RepUserName = txtRepUserName.Text.Trim();
                serDoc.RepUserTel = txtRepUserTel.Text.Trim();
                serDoc.RepDeptNo = Convert.ToInt32(drpGroup.SelectedValue);
                serDoc.RepTitle = txtRepTitle.Text.Trim();
                serDoc.RepContent = txtRepContent.Text.Trim();
                serDoc.ServProbType = Convert.ToInt32(drpServProbType.SelectedValue);
                serDoc.ServTrobType = Convert.ToInt32(drpServTrobType.SelectedValue);
                if (UpPhoto())
                {
                    serDoc.Accessories = urlPath;
                }

                serDoc.DocDat = DateTime.Now;
                serDoc.DocSolvePSN = Convert.ToInt32(txtFirstUserID.Text.Trim());
                serDoc.Statue = 1; //服务单状态(0:未解决 1:已解决)

                
                serAllocDoc.DOCNO = txtServDocNo.Text.Trim();

                //首次派单
                serAllocDoc.AllotPSNID = Convert.ToInt32(txtFirstUserID.Text.Trim());
                serAllocDoc.AllotNoticeType = FstUserNotify;
                if (txtFirstAttID.Text.Trim() != "")
                {
                    //首次派单关注人
                    serAllocDoc.AttentPSNID = Convert.ToInt32(txtFirstAttID.Text.Trim());
                    serAllocDoc.AttentNoticeType = FstAttPSNNotify;
                }
                
                
                serAllocDoc.HardwareInfo = txtHardwareInfo.Text.Trim();
                serAllocDoc.HardNoticeType = HardNoticeType;
                serAllocDoc.IPAddressInfo = txtIPAddressInfo.Text.Trim();
                serAllocDoc.IPNotifyType = IpAddrNoticeType;
                serAllocDoc.Solution = txtSolution.Text.Trim();
                serAllocDoc.Content = txtContent.Text.Trim();
                serAllocDoc.Status = 0;
                serAllocDoc.DealWith = true;
                serAllocDoc.DelegUID = Common.Get_UserID;

                //保存派单信息
                its_ServiceDocCs sdCs = new its_ServiceDocCs();
                sdCs.its_ServiceDoc_Add(serDoc, serAllocDoc);


                string tempStr = "";
                
                //首次派单人员通知
                tempStr = "您有一条待处理服务单：" + txtServDocNo.Text.Trim() + "，请及时处理。";
                switch (serAllocDoc.AllotNoticeType)
                {
                    case 1:
                        sdCs.SendMailTo(serAllocDoc.AllotPSNID, lblMailAddr.Text.Trim(), lblMailServer.Text.Trim(), lblMailUser.Text.Trim(), lblMailPwd.Text.Trim(), "派单信息通知", tempStr);
                        break;
                    case 2:
                        sdCs.SendMsgTo(serAllocDoc.AllotPSNID,tempStr);
                        break;
                    case 3:
                        sdCs.SendMsgTo(serAllocDoc.AllotPSNID, tempStr);
                        sdCs.SendMailTo(serAllocDoc.AllotPSNID, lblMailAddr.Text.Trim(), lblMailServer.Text.Trim(), lblMailUser.Text.Trim(), lblMailPwd.Text.Trim(), "派单信息通知", tempStr);
                        break;
                    default:
                        break;
                }

                if (txtFirstAttID.Text.Trim() != "")
                {
                    tempStr = "您有一条关注的服务单：" + txtServDocNo.Text.Trim() + "，请及时处理。";
                    //首次派单关注人通知
                    switch (serAllocDoc.AttentNoticeType)
                    {
                        case 1:
                            sdCs.SendMailTo(serAllocDoc.AttentPSNID, lblMailAddr.Text.Trim(), lblMailServer.Text.Trim(), lblMailUser.Text.Trim(), lblMailPwd.Text.Trim(), "派单信息通知", tempStr);
                            break;
                        case 2:
                            sdCs.SendMsgTo(serAllocDoc.AttentPSNID, tempStr);
                            break;
                        case 3:
                            sdCs.SendMsgTo(serAllocDoc.AttentPSNID, tempStr);
                            sdCs.SendMailTo(serAllocDoc.AttentPSNID, lblMailAddr.Text.Trim(), lblMailServer.Text.Trim(), lblMailUser.Text.Trim(), lblMailPwd.Text.Trim(), "派单信息通知", tempStr);
                            break;
                        default:
                            break;
                    }
                }

                //硬件更换通知
                switch (serAllocDoc.HardNoticeType)
                {
                    case 1:
                        sdCs.SendMailToHardwareAdmin(lblMailAddr.Text.Trim(), lblMailServer.Text.Trim(), lblMailUser.Text.Trim(), lblMailPwd.Text.Trim(), "硬件更换信息通知", serAllocDoc.HardwareInfo);
                        break;
                    case 2:
                        sdCs.SendMsgToHardWareAdmin(serAllocDoc.HardwareInfo);
                        break;
                    case 3:
                        sdCs.SendMsgToHardWareAdmin(serAllocDoc.HardwareInfo);
                        sdCs.SendMailToHardwareAdmin(lblMailAddr.Text.Trim(), lblMailServer.Text.Trim(), lblMailUser.Text.Trim(), lblMailPwd.Text.Trim(), "硬件更换信息通知", serAllocDoc.HardwareInfo);
                        break;
                    default:
                        break;
                }

                //IP地址更换通知
                switch (serAllocDoc.IPNotifyType)
                {
                    case 1:
                        sdCs.SendMailToPCAdmin(lblMailAddr.Text.Trim(), lblMailServer.Text.Trim(), lblMailUser.Text.Trim(), lblMailPwd.Text.Trim(), "IP地址更换通知", serAllocDoc.IPAddressInfo);
                        break;
                    case 2:
                        sdCs.SendMsgToPCAdmin(serAllocDoc.IPAddressInfo);
                        break;
                    case 3:
                        sdCs.SendMsgToPCAdmin(serAllocDoc.IPAddressInfo);
                        sdCs.SendMailToPCAdmin(lblMailAddr.Text.Trim(), lblMailServer.Text.Trim(), lblMailUser.Text.Trim(), lblMailPwd.Text.Trim(), "IP地址更换通知", serAllocDoc.IPAddressInfo);
                        break;
                    default:
                        break;
                }

            }
            catch (Exception ex)
            {
                this.ClientScript.RegisterStartupScript(this.GetType(), "key5", "<script>alert('服务单保存出错!" + ex.Message.Replace("\n", "\\n") + "');</script>");
                //this.ClientScript.RegisterStartupScript(this.GetType(), "key5", "<script>alert('服务单保存出错!"+ex.Message.Replace("\n","\\n")');</script>");
                FileTxtLogs.WriteLog("服务单保存出错,错误原因:" + ex.Message);
                return;
            }
            EventMessage.MessageBox(1, "保存成功", "服务单保存成功!", Icon_Type.OK, this.Request.Url.ToString());
        }

        private void DocClose()
        {
            try
            {
                //服务单类
                its_ServiceDoc serDoc = new its_ServiceDoc();
                //首次派单
                its_ServiceAllotDoc serAllocDoc = new its_ServiceAllotDoc();
                //二次派单
                its_ServiceAllotDoc serSecAllocDoc = new its_ServiceAllotDoc();


                serDoc.ServDocNo = txtServDocNo.Text.Trim();
                serDoc.RepUserNO = txtRepUserNO.Text.Trim();
                serDoc.RepUserName = txtRepUserName.Text.Trim();
                serDoc.RepUserTel = txtRepUserTel.Text.Trim();
                serDoc.RepDeptNo = Convert.ToInt32(drpGroup.SelectedValue);
                serDoc.RepTitle = txtRepTitle.Text.Trim();
                serDoc.RepContent = txtRepContent.Text.Trim();
                serDoc.ServProbType = Convert.ToInt32(drpServProbType.SelectedValue);
                serDoc.ServTrobType = Convert.ToInt32(drpServTrobType.SelectedValue);
                if (UpPhoto())
                {
                    serDoc.Accessories = urlPath;
                }
                serDoc.DocDat = DateTime.Now;
                serDoc.Statue = 0;  //服务单状态(0:未解决 1:已解决)


                serAllocDoc.DOCNO = txtServDocNo.Text.Trim();

                serAllocDoc.AllotPSNID = Convert.ToInt32(txtFirstUserID.Text.Trim());
                serAllocDoc.AllotNoticeType = FstUserNotify;
                if (txtFirstAttID.Text.Trim() != "")
                {
                    serAllocDoc.AttentPSNID = Convert.ToInt32(txtFirstAttID.Text.Trim());
                    serAllocDoc.AttentNoticeType = FstAttPSNNotify;
                }

                serAllocDoc.HardwareInfo = txtHardwareInfo.Text.Trim();
                serAllocDoc.HardNoticeType = HardNoticeType;
                serAllocDoc.IPAddressInfo = txtIPAddressInfo.Text.Trim();
                serAllocDoc.IPNotifyType = IpAddrNoticeType;
                serAllocDoc.Solution = txtSolution.Text.Trim();
                serAllocDoc.Content = txtContent.Text.Trim();
                serAllocDoc.Status = 0;
                serAllocDoc.DelegUID = Common.Get_UserID;

                if (chkSecAlloc.Checked)
                {
                    serAllocDoc.DealWith = true;
                }
                else
                {
                    serAllocDoc.DealWith = false;
                }


                if (chkSecAlloc.Checked)
                {
                    if (txtSecUserID.Text.Trim() == "")
                    {
                        this.ClientScript.RegisterStartupScript(this.GetType(), "key6", "<script>alert('请选择二次派单人员!');</script>");
                        return;
                    }


                    serSecAllocDoc.DOCNO = txtServDocNo.Text.Trim();
                    serSecAllocDoc.AllotPSNID = Convert.ToInt32(txtSecUserID.Text.Trim());
                    serSecAllocDoc.AllotNoticeType = SecUserNotify;
                    if (txtSecAttID.Text.Trim() != "")
                    {
                        serSecAllocDoc.AttentPSNID = Convert.ToInt32(txtSecAttID.Text.Trim());
                        serSecAllocDoc.AttentNoticeType = SecAttNotify;
                    }
                    serSecAllocDoc.Status = 1;
                    serSecAllocDoc.DealWith = false;
                    serSecAllocDoc.DelegUID = Common.Get_UserID;
                }

                its_ServiceDocCs sdCs = new its_ServiceDocCs();

                if (chkSecAlloc.Checked)
                {

                    sdCs.its_ServiceDoc_Add(serDoc, serAllocDoc, serSecAllocDoc);
                }
                else
                {

                    sdCs.its_ServiceDoc_Add(serDoc, serAllocDoc);
                }



                //首次派单人员通知
                string tempStr = "您有一条待处理服务单：" + txtServDocNo.Text.Trim() + "，请及时处理。";
                switch (serAllocDoc.AllotNoticeType)
                {
                    case 1:
                        sdCs.SendMailTo(serAllocDoc.AllotPSNID, lblMailAddr.Text.Trim(), lblMailServer.Text.Trim(), lblMailUser.Text.Trim(), lblMailPwd.Text.Trim(), "派单信息通知", tempStr);
                        break;
                    case 2:
                        sdCs.SendMsgTo(serAllocDoc.AllotPSNID, tempStr);
                        break;
                    case 3:
                        sdCs.SendMsgTo(serAllocDoc.AllotPSNID, tempStr);
                        sdCs.SendMailTo(serAllocDoc.AllotPSNID, lblMailAddr.Text.Trim(), lblMailServer.Text.Trim(), lblMailUser.Text.Trim(), lblMailPwd.Text.Trim(), "派单信息通知", tempStr);
                        break;
                    default:
                        break;
                }
                if (txtFirstAttID.Text.Trim() != "")
                {
                    tempStr = "您有一条关注的服务单：" + txtServDocNo.Text.Trim() + "，请及时处理。";
                    //首次派单关注人通知
                    switch (serAllocDoc.AttentNoticeType)
                    {
                        case 1:
                            sdCs.SendMailTo(serAllocDoc.AttentPSNID, lblMailAddr.Text.Trim(), lblMailServer.Text.Trim(), lblMailUser.Text.Trim(), lblMailPwd.Text.Trim(), "派单信息通知", tempStr);
                            break;
                        case 2:
                            sdCs.SendMsgTo(serAllocDoc.AttentPSNID, tempStr);
                            break;
                        case 3:
                            sdCs.SendMsgTo(serAllocDoc.AttentPSNID, tempStr);
                            sdCs.SendMailTo(serAllocDoc.AttentPSNID, lblMailAddr.Text.Trim(), lblMailServer.Text.Trim(), lblMailUser.Text.Trim(), lblMailPwd.Text.Trim(), "派单信息通知", tempStr);
                            break;
                        default:
                            break;
                    }
                }

                //硬件更换通知
                switch (serAllocDoc.HardNoticeType)
                {
                    case 1:
                        sdCs.SendMailToHardwareAdmin(lblMailAddr.Text.Trim(), lblMailServer.Text.Trim(), lblMailUser.Text.Trim(), lblMailPwd.Text.Trim(), "硬件更换信息通知", serAllocDoc.HardwareInfo);
                        break;
                    case 2:
                        sdCs.SendMsgToHardWareAdmin(serAllocDoc.HardwareInfo);
                        break;
                    case 3:
                        sdCs.SendMsgToHardWareAdmin(serAllocDoc.HardwareInfo);
                        sdCs.SendMailToHardwareAdmin(lblMailAddr.Text.Trim(), lblMailServer.Text.Trim(), lblMailUser.Text.Trim(), lblMailPwd.Text.Trim(), "硬件更换信息通知", serAllocDoc.HardwareInfo);
                        break;
                    default:
                        break;
                }

                //IP地址更换通知
                switch (serAllocDoc.IPNotifyType)
                {
                    case 1:
                        sdCs.SendMailToPCAdmin(lblMailAddr.Text.Trim(), lblMailServer.Text.Trim(), lblMailUser.Text.Trim(), lblMailPwd.Text.Trim(), "IP地址更换通知", serAllocDoc.IPAddressInfo);
                        break;
                    case 2:
                        sdCs.SendMsgToPCAdmin(serAllocDoc.IPAddressInfo);
                        break;
                    case 3:
                        sdCs.SendMsgToPCAdmin(serAllocDoc.IPAddressInfo);
                        sdCs.SendMailToPCAdmin(lblMailAddr.Text.Trim(), lblMailServer.Text.Trim(), lblMailUser.Text.Trim(), lblMailPwd.Text.Trim(), "IP地址更换通知", serAllocDoc.IPAddressInfo);
                        break;
                    default:
                        break;
                }
                //二次派单通知
                if (chkSecAlloc.Checked)
                {

                    tempStr = "您有一条待处理的二次派单：" + txtServDocNo.Text.Trim() + "，请及时处理。";
                    switch (serSecAllocDoc.AllotNoticeType)
                    {
                        case 1:
                            sdCs.SendMailTo(serSecAllocDoc.AllotPSNID, lblMailAddr.Text.Trim(), lblMailServer.Text.Trim(), lblMailUser.Text.Trim(), lblMailPwd.Text.Trim(), "派单信息通知", tempStr);
                            break;
                        case 2:
                            sdCs.SendMsgTo(serSecAllocDoc.AllotPSNID, tempStr);
                            break;
                        case 3:
                            sdCs.SendMsgTo(serSecAllocDoc.AllotPSNID, tempStr);
                            sdCs.SendMailTo(serSecAllocDoc.AllotPSNID, lblMailAddr.Text.Trim(), lblMailServer.Text.Trim(), lblMailUser.Text.Trim(), lblMailPwd.Text.Trim(), "派单信息通知", tempStr);
                            break;
                        default:
                            break;
                    }

                    if (txtSecAttID.Text.Trim() != "")
                    {
                        tempStr = "您有一条关注的二次派单：" + txtServDocNo.Text.Trim() + "，请及时处理。";

                        switch (serSecAllocDoc.AttentNoticeType)
                        {
                            case 1:
                                sdCs.SendMailTo(serSecAllocDoc.AttentPSNID, lblMailAddr.Text.Trim(), lblMailServer.Text.Trim(), lblMailUser.Text.Trim(), lblMailPwd.Text.Trim(), "派单信息通知", tempStr);
                                break;
                            case 2:
                                sdCs.SendMsgTo(serSecAllocDoc.AttentPSNID, tempStr);
                                break;
                            case 3:
                                sdCs.SendMsgTo(serSecAllocDoc.AttentPSNID, tempStr);
                                sdCs.SendMailTo(serSecAllocDoc.AttentPSNID, lblMailAddr.Text.Trim(), lblMailServer.Text.Trim(), lblMailUser.Text.Trim(), lblMailPwd.Text.Trim(), "派单信息通知", tempStr);
                                break;
                            default:
                                break;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                this.ClientScript.RegisterStartupScript(this.GetType(), "key6", "<script>alert('服务单二次派单保存出错!" + ex.Message.Replace("\n", "\\n") + "');</script>");
                //this.ClientScript.RegisterStartupScript(this.GetType(), "key6", "<script>alert('服务单二次派单保存出错!');</script>");
                FileTxtLogs.WriteLog("服务单二次派单保存出错,错误原因:" + ex.Message);
                return;
            }

            EventMessage.MessageBox(1, "保存成功", "服务单保存成功!", Icon_Type.OK, this.Request.Url.ToString());
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            if (Check())
            {
                //存在二次派单则只能点击问题关闭
                if (chkSecAlloc.Checked)
                {
                    this.ClientScript.RegisterStartupScript(this.GetType(), "key7", "<script>alert('存在二次派单,只能点击『完成』!');</script>");
                    return;
                }
                DocFinish();
            }
        }

        protected void BtnClose_Click(object sender, EventArgs e)
        {
            if (Check())
            {
                DocClose();
            }
        }

        private void GetMailInfo()
        {
            its_FieldValueCs fvCs = new its_FieldValueCs();
            sys_FieldValue fv = new sys_FieldValue();

            fv.V_F_Key = "MailServer";
            DataTable dtMailServer = fvCs.Field_SelectInfoByF_Key(fv);
            
            fv.V_F_Key = "MailUser";
            DataTable dtMailUser = fvCs.Field_SelectInfoByF_Key(fv);
            
            fv.V_F_Key = "MailPwd";
            DataTable dtMailPwd = fvCs.Field_SelectInfoByF_Key(fv);

   
            fv.V_F_Key = "MailAddr";
            DataTable dtMailAddr = fvCs.Field_SelectInfoByF_Key(fv);

            
            lblMailServer.Text = dtMailServer.Rows[0]["V_Text"].ToString();
            lblMailUser.Text = dtMailUser.Rows[0]["V_Text"].ToString();
            lblMailPwd.Text = dtMailPwd.Rows[0]["V_Text"].ToString();
            lblMailAddr.Text = dtMailAddr.Rows[0]["V_Text"].ToString();
        }

        protected void btnGetUser_Click(object sender, EventArgs e)
        {
            txtRepUserName.Text = "";
            txtRepUserID.Text = "";
            txtRepUserTel.Text = "";

            if (txtRepUserNO.Text.Trim() == "")
            {
                return;
            }
            sys_User su = new sys_User();
            //su.U_CName = this.txt_CName.Text.Trim();
            //su.U_GroupID = int.Parse(this.drpGroup.SelectedValue);
            su.U_UserNO = this.txtRepUserNO.Text.Trim();
            //根据条件查找用户
            sys_UserCs suCs = new sys_UserCs();
            DataTable dt = suCs.User_SelectInfoByU_CNameAndU_GroupIDAndU_UserNO(su);
            //填充信息
            if (dt.Rows.Count > 0)
            {
                this.txtRepUserName.Text = dt.Rows[0]["U_CName"].ToString();
                this.txtRepUserID.Text = dt.Rows[0]["UserID"].ToString();
                this.drpGroup.SelectedValue = dt.Rows[0]["U_GroupID"].ToString();
                this.txtRepUserTel.Text = dt.Rows[0]["U_Extension"].ToString();
            }

        }
    }
}
